home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / actionrp / lrogue0.1 / lrogue0 / rogue / ring.c < prev    next >
C/C++ Source or Header  |  1992-02-05  |  6KB  |  289 lines

  1. /*
  2.  * ring.c
  3.  *
  4.  * This source herein may be modified and/or distributed by anybody who
  5.  * so desires, with the following restrictions:
  6.  *    1.)  No portion of this notice shall be removed.
  7.  *    2.)  Credit shall not be taken for the creation of this source.
  8.  *    3.)  This code is not to be traded, sold, or used for personal
  9.  *         gain or profit.
  10.  *
  11.  */
  12.  
  13. #include "rogue.h"
  14.  
  15. char *left_or_right = "left or right hand?";
  16. char *no_ring = "there's no ring on that hand";
  17. short stealthy, r_rings, add_strength, e_rings, regeneration, ring_exp;
  18. short auto_search;
  19. boolean r_teleport, r_see_invisible, sustain_strength, maintain_armor;
  20.  
  21. extern char *curse_message;
  22. extern boolean wizard;
  23.  
  24. put_on_ring()
  25. {
  26.     short ch;
  27.     char desc[DCOLS];
  28.     object *ring;
  29.  
  30.     if (r_rings == 2) {
  31.         message("wearing two rings already", 0);
  32.         return;
  33.     }
  34.     if ((ch = pack_letter("put on what?", RING)) == CANCEL) {
  35.         return;
  36.     }
  37.     if (!(ring = get_letter_object(ch))) {
  38.         message("no such item.", 0);
  39.         return;
  40.     }
  41.     if (!(ring->what_is & RING)) {
  42.         message("that's not a ring", 0);
  43.         return;
  44.     }
  45.     if (ring->in_use_flags & (ON_LEFT_HAND | ON_RIGHT_HAND)) {
  46.         message("that ring is already being worn", 0);
  47.         return;
  48.     }
  49.     if (r_rings == 1) {
  50.         ch = (rogue.left_ring ? 'r' : 'l');
  51.     } else {
  52.         message(left_or_right, 0);
  53.         do {
  54.             ch = rgetchar();
  55.         } while ((ch != CANCEL) && (ch != 'l') && (ch != 'r') && (ch != '\n') &&
  56.                  (ch != '\r'));
  57.     }
  58.     if ((ch != 'l') && (ch != 'r')) {
  59.         check_message();
  60.         return;
  61.     }
  62.     if (((ch == 'l') && rogue.left_ring)||((ch == 'r') && rogue.right_ring)) {
  63.         check_message();
  64.         message("there's already a ring on that hand", 0);
  65.         return;
  66.     }
  67.     if (ch == 'l') {
  68.         do_put_on(ring, 1);
  69.     } else {
  70.         do_put_on(ring, 0);
  71.     }
  72.     ring_stats(1);
  73.     check_message();
  74.     get_desc(ring, desc);
  75.     message(desc, 0);
  76.     (void) reg_move();
  77. }
  78.  
  79. /*
  80.  * Do not call ring_stats() from within do_put_on().  It will cause
  81.  * serious problems when do_put_on() is called from read_pack() in restore().
  82.  */
  83.  
  84. do_put_on(ring, on_left)
  85. object *ring;
  86. boolean on_left;
  87. {
  88.     if (on_left) {
  89.         ring->in_use_flags |= ON_LEFT_HAND;
  90.         rogue.left_ring = ring;
  91.     } else {
  92.         ring->in_use_flags |= ON_RIGHT_HAND;
  93.         rogue.right_ring = ring;
  94.     }
  95. }
  96.  
  97. remove_ring()
  98. {
  99.     boolean left = 0, right = 0;
  100.     short ch;
  101.     char buf[DCOLS];
  102.     object *ring;
  103.  
  104.     if (r_rings == 0) {
  105.         inv_rings();
  106.     } else if (rogue.left_ring && !rogue.right_ring) {
  107.         left = 1;
  108.     } else if (!rogue.left_ring && rogue.right_ring) {
  109.         right = 1;
  110.     } else {
  111.         message(left_or_right, 0);
  112.         do {
  113.             ch = rgetchar();
  114.         } while ((ch != CANCEL) && (ch != 'l') && (ch != 'r') &&
  115.             (ch != '\n') && (ch != '\r'));
  116.         left = (ch == 'l');
  117.         right = (ch == 'r');
  118.         check_message();
  119.     }
  120.     if (left || right) {
  121.         if (left) {
  122.             if (rogue.left_ring) {
  123.                 ring = rogue.left_ring;
  124.             } else {
  125.                 message(no_ring, 0);
  126.             }
  127.         } else {
  128.             if (rogue.right_ring) {
  129.                 ring = rogue.right_ring;
  130.             } else {
  131.                 message(no_ring, 0);
  132.             }
  133.         }
  134.         if (ring->is_cursed) {
  135.             message(curse_message, 0);
  136.         } else {
  137.             un_put_on(ring);
  138.             (void) strcpy(buf, "removed ");
  139.             get_desc(ring, buf + 8);
  140.             message(buf, 0);
  141.             (void) reg_move();
  142.         }
  143.     }
  144. }
  145.  
  146. un_put_on(ring)
  147. object *ring;
  148. {
  149.     if (ring && (ring->in_use_flags & ON_LEFT_HAND)) {
  150.         ring->in_use_flags &= (~ON_LEFT_HAND);
  151.         rogue.left_ring = 0;
  152.     } else if (ring && (ring->in_use_flags & ON_RIGHT_HAND)) {
  153.         ring->in_use_flags &= (~ON_RIGHT_HAND);
  154.         rogue.right_ring = 0;
  155.     }
  156.     ring_stats(1);
  157. }
  158.  
  159. gr_ring(ring, assign_wk)
  160. object *ring;
  161. boolean assign_wk;
  162. {
  163.     ring->what_is = RING;
  164.     if (assign_wk) {
  165.         ring->which_kind = get_rand(0, (RINGS - 1));
  166.     }
  167.     ring->class = 0;
  168.  
  169.     switch(ring->which_kind) {
  170.     /*
  171.     case STEALTH:
  172.         break;
  173.     case SLOW_DIGEST:
  174.         break;
  175.     case REGENERATION:
  176.         break;
  177.     case R_SEE_INVISIBLE:
  178.         break;
  179.     case SUSTAIN_STRENGTH:
  180.         break;
  181.     case R_MAINTAIN_ARMOR:
  182.         break;
  183.     case SEARCHING:
  184.         break;
  185.     */
  186.     case R_TELEPORT:
  187.         ring->is_cursed = 1;
  188.         break;
  189.     case ADD_STRENGTH:
  190.     case DEXTERITY:
  191.         while ((ring->class = (get_rand(0, 4) - 2)) == 0) ;
  192.         ring->is_cursed = (ring->class < 0);
  193.         break;
  194.     case ADORNMENT:
  195.         ring->is_cursed = coin_toss();
  196.         break;
  197.     }
  198. }
  199.  
  200. inv_rings()
  201. {
  202.     char buf[DCOLS];
  203.  
  204.     if (r_rings == 0) {
  205.         message("not wearing any rings", 0);
  206.     } else {
  207.         if (rogue.left_ring) {
  208.             get_desc(rogue.left_ring, buf);
  209.             message(buf, 0);
  210.         }
  211.         if (rogue.right_ring) {
  212.             get_desc(rogue.right_ring, buf);
  213.             message(buf, 0);
  214.         }
  215.     }
  216.     if (wizard) {
  217.         sprintf(buf, "ste %d, r_r %d, e_r %d, r_t %d, s_s %d, a_s %d, reg %d, r_e %d, s_i %d, m_a %d, aus %d",
  218.             stealthy, r_rings, e_rings, r_teleport, sustain_strength,
  219.             add_strength, regeneration, ring_exp, r_see_invisible,
  220.             maintain_armor, auto_search);
  221.         message(buf, 0);
  222.     }
  223. }
  224.  
  225. ring_stats(pr)
  226. boolean pr;
  227. {
  228.     short i;
  229.     object *ring;
  230.  
  231.     stealthy = 0;
  232.     r_rings = 0;
  233.     e_rings = 0;
  234.     r_teleport = 0;
  235.     sustain_strength = 0;
  236.     add_strength = 0;
  237.     regeneration = 0;
  238.     ring_exp = 0;
  239.     r_see_invisible = 0;
  240.     maintain_armor = 0;
  241.     auto_search = 0;
  242.  
  243.     for (i = 0; i < 2; i++) {
  244.         if (!(ring = ((i == 0) ? rogue.left_ring : rogue.right_ring))) {
  245.             continue;
  246.         }
  247.         r_rings++;
  248.         e_rings++;
  249.         switch(ring->which_kind) {
  250.         case STEALTH:
  251.             stealthy++;
  252.             break;
  253.         case R_TELEPORT:
  254.             r_teleport = 1;
  255.             break;
  256.         case REGENERATION:
  257.             regeneration++;
  258.             break;
  259.         case SLOW_DIGEST:
  260.             e_rings -= 2;
  261.             break;
  262.         case ADD_STRENGTH:
  263.             add_strength += ring->class;
  264.             break;
  265.         case SUSTAIN_STRENGTH:
  266.             sustain_strength = 1;
  267.             break;
  268.         case DEXTERITY:
  269.             ring_exp += ring->class;
  270.             break;
  271.         case ADORNMENT:
  272.             break;
  273.         case R_SEE_INVISIBLE:
  274.             r_see_invisible = 1;
  275.             break;
  276.         case MAINTAIN_ARMOR:
  277.             maintain_armor = 1;
  278.             break;
  279.         case SEARCHING:
  280.             auto_search += 2;
  281.             break;
  282.         }
  283.     }
  284.     if (pr) {
  285.         print_stats(STAT_STRENGTH);
  286.         relight();
  287.     }
  288. }
  289.